home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / dev / obero / dialogs.lha / oberonv4 / system1 / DialogClocks.Mod (.txt) < prev    next >
Oberon Text  |  1995-12-25  |  5KB  |  147 lines

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 16 Dec 94
  6. Syntax10b.Scn.Fnt
  7. MODULE DialogClocks;
  8.     (** Markus Knasm
  9. ller 14 Sep 94 - 
  10.     (* This sourcecode uses parts of ClockElems - gri 18.3.91 *)
  11.     IMPORT DialogFrames, Dialogs, DialogTexts, Display, Fonts, GraphicUtils, In, Input, Oberon, TextFrames, Texts, Viewers;
  12.     CONST
  13.         W* = 60; H* = 20; MM = 1;
  14.         ticks = 300; (* Oberon.Time ticks per second*)
  15.     TYPE
  16.         Item* = POINTER TO ItemDesc;
  17.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  18.         END;
  19.         Time* = RECORD timeStamp*, dateStamp*: LONGINT END;
  20.         NotifyMsg = RECORD(Display.FrameMsg) new: Time END;
  21.         old*: Time; (** displayed Time *)    
  22.         wakeUp: LONGINT; (* overflow in 82.8 days *)
  23.         fnt: Fonts.Font;
  24.         Task: Oberon.Task;
  25.     PROCEDURE Format (time: LONGINT; VAR s: ARRAY OF CHAR);
  26.         VAR i: INTEGER;
  27.         PROCEDURE Pair (x: LONGINT);
  28.         BEGIN
  29.             s[i] := CHR(x DIV 10 + 30H); INC(i);
  30.             s[i] := CHR(x MOD 10 + 30H); INC(i)
  31.         END Pair;
  32.     BEGIN 
  33.         i := 0;
  34.         Pair(time DIV 4096 MOD 32); s[i] := ":"; INC(i);
  35.         Pair(time DIV 64 MOD 64); s[i] := ":"; INC(i);
  36.         Pair(time MOD 64); s[i] := 0X
  37.     END Format;
  38.     PROCEDURE (c: Item) Draw* (x, y: INTEGER; f: Display.Frame);
  39.     (** displays the object at (x, y) in frame f *)
  40.         VAR mode, w, h, ox, oy, cx, yh: INTEGER; str: ARRAY 12 OF CHAR; 
  41.     BEGIN
  42.         c.GetDim (ox, oy, w, h);
  43.         IF c.selected THEN mode := Display.invert ELSE mode := Display.paint END;
  44.         yh := y + (h DIV 2) - ((fnt.minY + fnt.maxY) DIV 2);
  45.         Format (old.timeStamp, str);
  46.         IF h - (yh - y) > fnt.maxY THEN
  47.             GraphicUtils.DrawString (f, str, x + 3, yh, w - 4, fnt, mode, GraphicUtils.center, cx)
  48.         END
  49.     END Draw;
  50.     PROCEDURE (c: Item) Print* (x, y: INTEGER);
  51.     (** prints the object at printer coordinates (x, y)  *)
  52.         VAR w, h, ox, oy, cx, yh: INTEGER; str: ARRAY 12 OF CHAR; time: Time; fnth: LONGINT;
  53.     BEGIN
  54.         c.GetPDim (ox, oy, w, h);
  55.         fnth := ((fnt.maxY - fnt.minY) * Dialogs.dUnit) DIV Dialogs.pUnit DIV 2;
  56.         yh := y + (h DIV 2) - SHORT (fnth);
  57.         Oberon.GetClock (time.timeStamp, time.dateStamp);
  58.         Format (time.timeStamp, str);
  59.         IF h - (yh - y) > SHORT(fnt.maxY * Dialogs.dUnit DIV Dialogs.pUnit) THEN
  60.             GraphicUtils.PrintString (str, x + 3, yh, w - 4, fnt, GraphicUtils.center, cx)
  61.         END
  62.     END Print;
  63.     PROCEDURE (c: Item) Copy* (VAR dup: Dialogs.Object);
  64.     (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
  65.         VAR x: Item;
  66.     BEGIN
  67.         IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END;
  68.         c.Copy^ (dup);
  69.     END Copy;
  70.     PROCEDURE (c: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel);
  71.         VAR keysum: SET; t: Texts.Text;
  72.     BEGIN
  73.         IF keys = {MM} THEN 
  74.             keysum := keys;
  75.             REPEAT 
  76.                 Input.Mouse(keys, x, y); keysum := keysum + keys;
  77.                 Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
  78.             UNTIL keys = {};
  79.             IF (keysum = {MM}) & (c.cmd[0] # 0X) THEN 
  80.                 DialogTexts.GetParText (c.par, c.panel, t); 
  81.                 c.CallCmd (f, Viewers.This (x, y), t)
  82.             END
  83.         ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
  84.         END
  85.     END Track;
  86.     PROCEDURE (c: Item) Redraw* (f: Display.Frame; x, y: INTEGER; old, new: Time);
  87.     (** redraws the item at (x, y) in frame f - the time changed from old to new *)
  88.     BEGIN 
  89.         IF c.selected THEN RETURN END;
  90.         c.Hide; c.Restore
  91.     END Redraw;
  92.     PROCEDURE (c: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
  93.     (** handles messages which were sent to frame f *)
  94.         VAR x, y, w, h: INTEGER;
  95.     BEGIN
  96.         c.Handle^ (f, m);
  97.         WITH f: DialogFrames.Frame DO
  98.             WITH m: Oberon.InputMsg DO
  99.                 IF m.id = Oberon.track THEN c.Track (m.X, m.Y, m.keys, f, f.panel) END
  100.             | m: NotifyMsg DO
  101.                 c.GetDim (x, y, w, h); x := x + f.X; y := y + f.Y + f.H;
  102.                 c.Redraw (f, x, y, old, m.new)
  103.             ELSE
  104.             END
  105.         ELSE
  106.         END
  107.     END Handle;
  108.     PROCEDURE Clock;
  109.         VAR msg: NotifyMsg;
  110.     BEGIN
  111.         IF Oberon.Time () >= wakeUp THEN 
  112.             Oberon.GetClock (msg.new.timeStamp, msg.new.dateStamp);
  113.             IF msg.new.timeStamp # old.timeStamp THEN 
  114.                 wakeUp := Oberon.Time () + ticks * 15 DIV 16;
  115.                 Viewers.Broadcast (msg); old := msg.new
  116.             ELSE
  117.                 wakeUp := Oberon.Time () + ticks DIV 16
  118.             END
  119.         END
  120.     END Clock;
  121.     PROCEDURE Insert*;
  122.     (** Insert ([name] [x y w h] | ^ ) inserts a clock - item in the panel containing the caret position *)
  123.         VAR x, y, x1, y1, w, h: INTEGER; c: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; 
  124.     BEGIN 
  125.         NEW (c);  
  126.         DialogFrames.GetCaretPosition (p, x, y);
  127.         IF (p # NIL) THEN 
  128.             c.Init; In.Open; In.Name (name); 
  129.             IF ~In.Done THEN COPY ("", name); In.Open END;
  130.             c.SetName (name); 
  131.             In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
  132.             IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H 
  133.             ELSE
  134.                 IF w < 0 THEN w := W END;
  135.                 IF h < 0 THEN h := H END
  136.             END;
  137.             c.SetDim (x1, y1, w, h, FALSE); p.Insert (c, FALSE) 
  138.         ELSE
  139.             Dialogs.res := Dialogs.noPanelSelected
  140.         END;
  141.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogClocks") END;
  142.     END Insert;
  143. BEGIN
  144.     Oberon.GetClock (old.timeStamp, old.dateStamp); fnt := Fonts.This ("Syntax10.Scn.Fnt");
  145.     NEW (Task); Task.safe := FALSE; Task.handle := Clock; Oberon.Install (Task);
  146. END DialogClocks.
  147.